

function mov = loadTiffStack(filename,framerange)

showwaitbar = true;

temp = imfinfo(filename);
mov = zeros(temp(1).Height,temp(1).Width,length(temp));
if nargin > 1 && ~isempty(framerange)
    mov = mov(:,:,1:numel(framerange));
else
    framerange = 1:size(mov,3);
end
%for n = framerange
%    mov(:,:,n) = imread(filename,'ind',n);
%end

if showwaitbar
    f = waitbar(0,'loading tiff stack');
end
for n = 1:numel(framerange)
    mov(:,:,n) = imread(filename,'ind',framerange(n));
    if showwaitbar
        waitbar(n/numel(framerange),f,'loading tiff stack');
    end
end
if showwaitbar
    close(f)
end